﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dne.GridExt.Models;
using TestWeb.Models;

namespace TestWeb.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new TestIndexModel();
            model.Grid = new DneGrid("alef");
            model.Grid.Url = "/Home/GetGridData";
            model.Grid.Columns.Add(new Column("NameId", "Name"));
            model.Grid.Columns.Add(new Column("WartIndex", "Wartosc"));
            return View(model);
        }

        public class CosModel
        {
            public string NameId { get; set; }

            public string WartIndex { get; set; }

            public Guid Id { get; set; }
        }

        [HttpPost]
        public JsonResult GetGridData(GridModel gridModel)
        {
            var items = new List<CosModel>();
            items.Add(new CosModel { NameId = "cosTam1", WartIndex = "wartJakas1", Id = Guid.NewGuid() });
            items.Add(new CosModel { NameId = "cosTam2", WartIndex = "wartJakas2", Id = Guid.NewGuid() });
            return Json(ModelExtension.GridPaging(gridModel, items, x => new[]
                                                                             {
                                                                                 x.NameId,
                                                                                 x.WartIndex
                                                                             }, z => z.Id));
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
